var express = require('express');
var router = express.Router();
const {Article} = require('../models');
const { failure, success, NotFoundError } = require('../utils/response');

// 查询单条文章详情
router.get('/:id', async function(req, res, next) {
    try {
        const {id} = req.params
        const article = await Article.findByPk(id)
        if(!article){
            throw new NotFoundError(`ID为${id}的文章未找到`)
        }
        success(res,'查询文章成功',{article})
    } catch (error) {
        failure(res,error)
    }
    
});

module.exports = router